#ifndef ANIMATEDWIGET_H
#define ANIMATEDWIGET_H

#include <QWidget>
#include <QDebug>
#include <QPainter>
#include <QStateMachine>
#include <QState>
#include <QFinalState>
#include <QPropertyAnimation>
#include <QPaintEvent>
#include <QAbstractTransition>
#include <QEvent>
#include <QTimer>
#include <QtWebKit/QWebView>
#include <QtWebKit/QWebFrame>
#include <QFile>
#include <QBuffer>

class webWidget : public QWebView
{
    Q_OBJECT
public:
    explicit webWidget(QWidget *parent = 0);

signals:
    void leftButClicked();
    void rightButclicked();

protected:
//    void showEvent (QShowEvent*);
    void mouseReleaseEvent ( QMouseEvent * event );
    Qt::MouseButton leftButTrigger;
    Qt::MouseButton rightButTrigger;
};

class animationTransition : public QAbstractTransition
 {
 public:
    enum transType {show, hide, update};
    struct animationEvent : public QEvent
     {
        animationEvent(const transType &val) : QEvent(QEvent::Type(QEvent::User+1)), value(val)
        {}

         transType value;
     };

     animationTransition(const transType &value)
         : m_value(value) {}

 protected:
     bool eventTest(QEvent *e);
     void onTransition(QEvent *);

 private:
     transType m_value;
 };

class animatedWidget : public QWidget
{
Q_OBJECT
public:
    explicit animatedWidget(QWidget *parent = 0);
    ~animatedWidget();

    enum fillTypes {monoChrom, lineGrad, radialGrad};

    fillTypes fillType;

    QPoint topLeft;

    int setMessage(QString title, QString msg, QString imagePath);

    int setAnimation ();
    int updateState();

private:
    QSize defaultSize;
    QState* startState;
    QState* hideState;
    QState* showState;
    QFinalState *doneState;
    QStateMachine machine;

    QPropertyAnimation* opacityAnim;
    QPropertyAnimation* geometryAnim;

    animationTransition *showTransition;
    animationTransition *hideTransition;
    animationTransition *updateTransition;

    QWebView *message;

    QByteArray MakeImage (const QString& path);

    void paintEvent(QPaintEvent *event);

signals:
    void showWgt();
    void hideWgt();
    void finished();
    void updated();
    void activated();

public slots:
    void hideMe();
    void activMe();
    void testSlot();

private slots:
    void showMe();
    void finish();
    void updateMe();
    void debugMachine();
};

#endif // ANIMATEDWIGET_H
